import 'package:json_annotation/json_annotation.dart';

part 'order_page_data.g.dart';

@JsonSerializable()
class OrderPageData extends Object {
  int num;

  int totalFee;

  OrderPropPageResult orderPropPageResult;

  OrderPageData(
    this.num,
    this.totalFee,
    this.orderPropPageResult,
  );

  factory OrderPageData.fromJson(Map<String, dynamic> srcJson) => _$OrderPageDataFromJson(srcJson);

  Map<String, dynamic> toJson() => _$OrderPageDataToJson(this);
}

@JsonSerializable()
class OrderPropPageResult extends Object {
  int total;

  int totalPage;

  List<Order> items;

  OrderPropPageResult(
    this.total,
    this.totalPage,
    this.items,
  );

  factory OrderPropPageResult.fromJson(Map<String, dynamic> srcJson) => _$OrderPropPageResultFromJson(srcJson);

  Map<String, dynamic> toJson() => _$OrderPropPageResultToJson(this);
}

@JsonSerializable()
class Order extends Object {
  String unionOrderId;

  int orderType;

  String lockTableTime;

  int guests;

  int waiterId;

  String waiterOpenid;

  String waiterName;

  String waiterHeadImage;

  int storeId;

  String storeName;

  int tableId;

  int addTableId;

  String tableName;

  int orderStatus;

  int payStatus;

  int totalFee;

  int totalPrice;

  int tip;

  int couponFee;

  String essential;

  String channelName;

  String buyerMessage;

  int buyerIsRate;

  String waiterRate;

  String waiterRateDesc;

  String payTime;

  String payOrderId;

  String remark;

  String cancelReason;

  String couponRemark;

  int orderSource;

  int orderDeviceId;

  int isComplete;

  int invoiceType;

  int completeId;

  int decreaseAmount;

  int receiveAmount;

  int commodityDiscountFee;

  int orderDiscountFee;

  int orderDiscountType;

  int discountId;

  int customDiscountRate;

  String freeReason;

  String withDrawReason;

  String oppsiteOrderReason;

  String customDiscountReason;

  int withDrawAmount;

  int casherId;

  int chargeMoney;

  int freeDiscountAmount;

  int storeDiscountAmount;

  int oppositeOrderCount;

  String commodityDiscountDetail;

  String orderDiscountDetail;

  int sysDecreaseAmount;

  String openid;

  String nickname;

  String storeHeadImage;

  String openTableMan;

  String orderQrcode;

  int billStatus;

  String storeNo;

  List<OrderPayType> orderPayTypeList;

  String get payTypeName {
    var temp = '';
    orderPayTypeList.forEach((item) {
      temp += item.payTypeName;

      if (item != orderPayTypeList.last) {
        temp += '、';
      }
    });

    return temp;
  }

  String get orderStatusText {
    Map<int, String> map = {
      0: '新建',
      1: '已撤单',
      2: '未结账',
      3: '已结账',
      4: '已删除',
      5: '已退单',
    };
    return map[orderStatus] ?? '--';
  }

  String get orderDiscountText {
    Map<int, String> map = {
      0: '--',
      1: '整单折扣',
      2: '方案折扣',
      3: '满减',
      4: '自定义',
      5: '免单',
    };
    return map[orderDiscountType] ?? '--';
  }

  Order(
    this.unionOrderId,
    this.orderType,
    this.lockTableTime,
    this.guests,
    this.waiterId,
    this.waiterOpenid,
    this.waiterName,
    this.waiterHeadImage,
    this.storeId,
    this.storeName,
    this.tableId,
    this.addTableId,
    this.tableName,
    this.orderStatus,
    this.payStatus,
    this.totalFee,
    this.totalPrice,
    this.tip,
    this.couponFee,
    this.essential,
    this.channelName,
    this.buyerMessage,
    this.buyerIsRate,
    this.waiterRate,
    this.waiterRateDesc,
    this.payTime,
    this.payOrderId,
    this.remark,
    this.cancelReason,
    this.couponRemark,
    this.orderSource,
    this.orderDeviceId,
    this.isComplete,
    this.invoiceType,
    this.completeId,
    this.decreaseAmount,
    this.receiveAmount,
    this.commodityDiscountFee,
    this.orderDiscountFee,
    this.orderDiscountType,
    this.discountId,
    this.customDiscountRate,
    this.freeReason,
    this.withDrawReason,
    this.oppsiteOrderReason,
    this.customDiscountReason,
    this.withDrawAmount,
    this.casherId,
    this.chargeMoney,
    this.freeDiscountAmount,
    this.storeDiscountAmount,
    this.oppositeOrderCount,
    this.commodityDiscountDetail,
    this.orderDiscountDetail,
    this.sysDecreaseAmount,
    this.openid,
    this.nickname,
    this.storeHeadImage,
    this.openTableMan,
    this.orderQrcode,
    this.billStatus,
    this.storeNo,
    this.orderPayTypeList,
  );

  factory Order.fromJson(Map<String, dynamic> srcJson) => _$OrderFromJson(srcJson);

  Map<String, dynamic> toJson() => _$OrderToJson(this);
}

@JsonSerializable()
class OrderPayType extends Object {
  @JsonKey(name: 'actualMoney')
  int actualMoney;

  @JsonKey(name: 'chargeMoney')
  int chargeMoney;

  @JsonKey(name: 'id')
  int id;

  @JsonKey(name: 'payCount')
  int payCount;

  @JsonKey(name: 'payTime')
  String payTime;

  @JsonKey(name: 'payType')
  int payType;

  @JsonKey(name: 'payTypeName')
  String payTypeName;

  @JsonKey(name: 'storeId')
  int storeId;

  @JsonKey(name: 'totalFee')
  int totalFee;

  @JsonKey(name: 'unionOrderId')
  String unionOrderId;

  OrderPayType(
    this.actualMoney,
    this.chargeMoney,
    this.id,
    this.payCount,
    this.payTime,
    this.payType,
    this.payTypeName,
    this.storeId,
    this.totalFee,
    this.unionOrderId,
  );

  factory OrderPayType.fromJson(Map<String, dynamic> srcJson) => _$OrderPayTypeFromJson(srcJson);

  Map<String, dynamic> toJson() => _$OrderPayTypeToJson(this);
}
